import 'package:flutter/widgets.dart';

class UIHelper {
  static Rect findGlobalRect(GlobalKey key) {
    RenderBox? renderObject =
        key.currentContext!.findRenderObject() as RenderBox;

    var globalOffset = renderObject.localToGlobal(Offset.zero);

    var bounds = renderObject.paintBounds;
    bounds = bounds.translate(globalOffset.dx, globalOffset.dy);
    return bounds;
  }

  static Offset globalOffsetToLocal(GlobalKey key, Offset offsetGlobal) {
    RenderBox? renderObject =
        key.currentContext!.findRenderObject() as RenderBox;
    return renderObject.globalToLocal(offsetGlobal);
  }
}
